<?php
require_once dirname(__FILE__)  . '/../libs/DividendInterface.php';

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';

class DividendInterfaceTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_interface;
    
    protected function setUp()
    {
        $logger = Log::factory('console', '', '', array(), PEAR_LOG_INFO);
        $this->_logger = $logger;
        $this->_interface = new DividendInterface(DividendInterface::APP_ENV_TEST);
    }
    
    protected function tearDown()
    {
        
    }
    
    public function testOpen()
    {
        $this->markTestSkipped();
        $arr = array(
        	'appId'=>112233,
          	'spId'=>123,
            'sp'=>array('spName'=>'卡拉泽', 'spAddr' => '公司地址', 'spIntroduce' => '产品说明(选填)', 
	 'spPhone' => '公司电话', 'spMobile' => 1234567,  'spUser' => '负责人姓名', 'spEMail' => 'nokia@snda.com')
          );
        $result = $this->_interface->open($arr);
        if($this->_interface->getErrNo()) {
            print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());    
        }        
        $this->assertTrue($result !== false);        
        return $result;
    }
    
    public function testClose()
    {
        $this->markTestSkipped();
        $arr = array(
        	'appId'=>110078600,
          	'spId'=>1000135,
            'sp'=>array('spName'=>'卡拉泽', 'spAddr' => '公司地址', 'spIntroduce' => '产品说明(选填)', 
	 'spPhone' => '公司电话', 'spMobile' => 1234567,  'spUser' => '负责人姓名', 'spEMail' => 'nokia@snda.com')
          );
        $result = $this->_interface->close( $arr);
        if($this->_interface->getErrNo()) {
            print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());    
        }  
        $this->assertTrue($result !==false);
        return $result;
    }
    
    public function testUpdate()
    {
        //$this->markTestSkipped();
        $arr = array(
        	'appId'=>110078600,
          	'spId'=>1000135,
            'sp'=>array('spName'=>'卡拉泽', 'spAddr' => '公司地址', 'spIntroduce' => '产品说明(选填)', 
	 'spPhone' => '公司电话', 'spMobile' => 1234567,  'spUser' => '负责人姓名', 'spEMail' => 'nokia@snda.com')
          );
        $result = $this->_interface->update( $arr, DividendInterface::APP_ENV_PRODUCTION);     
        if($this->_interface->getErrNo()) {
            print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());    
        }     
        $this->assertTrue($result !== false);
        return $result;
    }
    
    public function testSync()
    {
        $this->markTestSkipped();
        $arr = array(
        	'appId'=>112233,
          	'testAccounts'=>array( 
                array('op'=>DividendInterface::TEST_ACCOUNTS_ADD, 'account'=>'mobfan', 'areaId'=>0),
                array('op'=>DividendInterface::TEST_ACCOUNTS_DELETE, 'account'=>'mobfan', 'areaId'=>1),
             ),
            'trustIp'=>array(
                array('ip'=>'127.0.0.1','areaId'=>1,'groupId'=>1, 'op'=>DividendInterface::TRUST_IP_DELETE)
            )
          );
        $result = $this->_interface->sync( $arr, DividendInterface::APP_ENV_PRODUCTION);
        $this->assertTrue($result !== false);
        print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());
        return $result;
    }
    
}
